# encoding    : utf-8 -*-                            
# @author     :
# @file       :   appium_app.py
# @Time       :   2025/1/2 10:49
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.common.touch_action import TouchAction   #坐标
import time


caps = {
  "appActivity": ".SplashActivity",
  "platformName": "Android",
  "platformVersion": "12",
  "deviceName": "127.0.0.1:7555",
  "appPackage": "com.sina.weibo"
}

url = "http://127.0.0.1:4723/wd/hub"
driver = webdriver.Remote(url,caps)
time.sleep(10)


#点击同意并继续
driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.LinearLayout/android.widget.TextView[3]").click()
time.sleep(5)

#点击发现按钮
TouchAction(driver).tap(x = 717, y = 2419).perform()
time.sleep(5)

#点击我知道了
driver.find_element(MobileBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.ImageView").click()
time.sleep(5)

#点击输入框
TouchAction(driver).tap(x = 842, y = 188).perform()
time.sleep(5)

driver.find_element(MobileBy.ID,"com.sina.weibo:id/tv_search_keyword").send_keys("8848")
time.sleep(5)


#模拟键盘按下enter键
driver.press_keycode(66)
time.sleep(5)


for i in range(10):
    # TouchAction(driver).press(x = 1,y = 1).move_to(x = 1,y =5 ).release().perform()
    driver.swipe(start_x=681,start_y=2150,end_x=681,end_y=661,duration=800)
    time.sleep(5)
    
    
driver.quit()


